// pages/ticket/ticket.js
const app = getApp();
Page({
  data: {
    bgTextStyle: 'dark',
    scrollTop: '200rpx',
    bgColor: '#ff0000',
    bgColorTop: '#00ff00',
    bgColorBottom: '#0000ff',
    nbTitle: '发票记录',
    nbLoading: false,
    nbFrontColor: '#000000',
    nbBackgroundColor: '#ffffff',
    pageStyle: "color:#333333;background-color: #f1f1f1;",
    navs:[
      {title: "首页",class:"", path:"/pages/index/index", icon: "", font: "fa fa-home"},
      {title: "信息",class:"", path:"", icon: "", font: "fa fa-comments-o"},
      {title: "维修",class:"", path:"", icon: "", font: "fa fa-wrench"},
      {title: "我的",class:"co", path:"/pages/mine/mine", icon: "", font: "fa fa-user-circle"},
    ],
    userInfo: {
      nickName: "",
      addr: "",
      phone: "",
      avatar: ""
    },
    ticketList:[],
    hasChange: false,
    ready: false
  },
  onLoad: function (options) {
  },
  onReady: function () {
  },
  onShow: function () {
    let v = this;
    if (app.globalData.token){
      v.getHistory();
    } else {
      console.log("app.doLogin");
      app.doLogin(v,v.getHistory);
    }
  },

  getHistory(){
    let v = this;
    v.setData({hasChange: false});
    let url = app.globalData.host + '/api/invoice/list';
    wx.request({
      url: url, data: {token: app.globalData.token},
      success (res) {
        let r = res.data;
        if(r.code == 200 && r.data) {
          let l = r.data.list || [];
          console.log("getHistory",l);
          v.setData({orderList: l});
        }
      }
    })
  },
  requestLink(ev){
    let v = this;
    let ds = ev.target.dataset;
    let uri = ds.link || '';
    if(!uri) return;
    app.globalData.linkUrl = uri;
    // wx.navigateTo({ url: "/pages/webview/webview?url="+ uri});
    console.log("requestLink",uri);
  },
  onSuccess: function (res) {
    console.log(res.detail);
  },
  onFail: function (res) {
    console.log(res);
  },
  onHide: function () {
  },
  onUnload: function () {
  },
  onPullDownRefresh: function () {
  },
  onReachBottom: function () {
  },

  onShareAppMessage: function () {
  }
})